{include file="common/head"}
<head>
<title>收付款录入</title>

<style type="text/css">
    #top{background: initial;border-bottom:1px solid rgba(0,0,0,0.1);max-width: 800px;}
    .mb-3{margin-bottom:0!important;}
</style>    
</head>
<body style="max-width: 800px;">
  <div id="header"></div>
  <div id="top" class="row text-center" style="background: #fff;height: 50px;">
    <div class="col-2 text-center"></div>
    <div class="col-8 text-center"><h3>收付款录入</h3></div>
    <div class="col-2 text"></div>
  </div>

    <div class="container p-5 my-2 d-grid" style="padding: 10px;">
      <input type="hidden" name="id" id="id" value="" />
      <br/>
      <div class="mb-3">
        <label for="name" class="form-label">收付款人确认:</label>
        <div class="input-group">
          <input type="hidden" class="form-control" id="customer_id" name="customer_id" value="" /></c>
          <input type="text" class="form-control" id="nameOrMobile" value="" placeholder="姓名或者手机号码" /></c>
          <button type="button" id="find_customer" class="btn btn-info  bi-search" >查找</button>
        </div>
      </div>
      <div class="row">
        <div class="col-2">
          <img id="img" src="/upload/logo.png" style="width:90%;border:1px solid #ccc;" />
        </div>        
        <div class="col-3">
          <label for="name" class="form-label">姓名:</label>
          <input type="text" class="form-control" id="name" name="name" value="" disabled />
        </div>
        <div class="col-3">
          <label for="mobile" class="form-label">手机号码:</label>
          <input type="text" class="form-control" id="mobile" name="mobile" value="" disabled />
        </div>
        <div class="col-4">
          <label for="id_card" class="form-label">身份证:</label>
          <input type="text" class="form-control" id="id_card" name="id_card" value="" disabled />
        </div>        
      </div>

      <hr/>


      <div class="mb-3 row">
        <div class="col">
          <label for="type" class="form-label">收付款类型：</label>
          <select name="type" id="type" class="form-control">
            {foreach $acc_type as $k=>$v}
              <option value="{$k}" {if $type==$k} selected {/if}>{$v} </option>
            {/foreach}
          </select>
        </div>


      </div> 

      <div class="mb-3 row">
        <div class="col">
          <label for="money" class="form-label">金额：</label>
          <input type="number" class="form-control" id="money" name="money" min="0" value="{$value}" style="color:green;font-weight: bold;" />          
        </div>        

    </div>

      <div class="mb-3 row">
        <div class="col">
          <label for="payment" class="form-label">支付方式：</label>
          <select name="payment" id="payment" class="form-control">
            <option value="" selected>未选择</option>
            {foreach $payment as $k=>$v}
              <option value="{$k}" >{$v}</option>
            {/foreach}
          </select>        
        </div>
    </div>   

      <div class="mb-3">
        <label for="memo" class="form-label">备注：</label>
        <input type="text" class="form-control" id="memo" name="memo" value="{$memo}" placeholder="学费缴费/退款/推广费..."   />
      </div>

      <br/>
      <button type="button" class="btn btn-info btn-block" id="save">提交</button>

      <br/>

      <div>
        <table class="table table-sm table-striped">
          <tr>
            <th>类型</th>
            <th>客户</th>
            <th>金额</th>
            <th>支付方式</th>
            <th>操作人</th>
            <th>日期</th>
            <th>状态</th>
          </tr>
          <tr>
            <td id="n_type"></td>
            <td id="n_cust"></td>
            <td id="n_money"></td>
            <td id="n_payment"></td>
            <td id="n_creater"></td>
            <td id="n_dt"></td>
            <td id="n_st"></td>
          </tr>
        </table>
      </div>

    </div>

<script type="text/javascript">
$(document).ready(function(){

    $("#find_customer").on('click',function(){

      if(!$("#nameOrMobile").val()) {
        layer.msg('请输入姓名或者手机号码查找！');return;
      }        
      $.post('/index.php/customer/getOne',{nameOrMobile:$("#nameOrMobile").val()},function(res){
        if(res.code){
          var data = res.data;
          var inviter = data.id;
          $("#customer_id").val(inviter);
          $("#name").val(data.name);
          $("#mobile").val(data.mobile);
          $("#id_card").val(data.id_card);
          $("#img").attr('src',data.image);

          layer.msg(res.msg);
        }else{
          layer.msg(res.msg);
        }

      })
    })

  $("#payment").on('change',function(){
    var payment = $(this).val();
    if(payment=='wx' || payment=='alipay'){
      var img = "/upload/"+payment+"_qrcode.png";
      console.log(img);
      layer.open({
                type:1,
                offset:['50px','400px'] ,
                title:"",           //商户微信收款码
                shade: 0.5,           //遮罩透明度
                maxmin: true,         //允许全屏最小化
                anim: 5,          //0-6的动画形式，-1不开启
                //area: ['350px', '340px'],   //宽高
                resize:true,        //允许被拉伸
                skin: 'layerdemo',      //注意这里，靠这个css自定义样式！！！！！
                scrollbar: false, //禁止滚动条 或者 弹窗页面》=页面大小，就没有滚动条))
                content:"<img src='"+img+"' style='width:350px;' />"
      });

    }})
  
  $("#save").on('click',function(){
      var cid=$("#customer_id").val();
      var money = $("#money").val();
      var memo = $("#memo").val();
      var gift = $("#gift").val();
      var type = $("#type").val();
      var payment = $("#payment").val();

      var type_msg=type<4?'收款':(type==2?'退款':'付款');

      if(!cid) {
        layer.msg('请先确定首付款人！');return;
      }
      if(isNaN(money) || money<=0) {
        layer.msg('无效的金额！');
        return false;
      }
      if(!payment) {
        layer.msg('请选择支付方式！');return;
      }      



      //询问框
      layer.confirm('本次'+type_msg+'金额：'+money+'，是否确定保存?', {btn: ['是的','不'],title:'确认' }, function(){
        $('form').submit();

        $.ajax({
          url:'/index.php/acc/money_io',
          data:{'cid':cid,'money':money,'type':type,'payment':payment,'memo':memo},
          success:function(res){
            var res=JSON.parse(res);
            if(res.code){
              layer.msg(res.msg+",请等待财务确认！");
              $("#customer_id").val('');

              $("#n_type").text(res.data.type_name);
              $("#n_cust").text(res.data.customer_id_name);
              $("#n_money").text(res.data.money);
              $("#n_payment").text(res.data.payment_name);
              $("#n_creater").text(res.data.creater_name);
              $("#n_dt").text(res.data.create_time);
              $("#n_st").text(res.data.status_name);
            }
              layer.msg(res.msg);

          }
        })
      }, function(){
        layer.msg("取消操作!");
        return 0;
      });

  })

})


</script>


</body>
</html>
